package org.apache.lucene.termvector;

import java.io.File;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

public class FileDocument
{
	public static Document Document(File f)
			throws java.io.FileNotFoundException
	{

		// make a new, empty document
		Document doc = new Document();

		// Add the path of the file as a field named "path". Use a field that is
		// indexed (i.e. searchable), but don't tokenize the field into words.
		doc.add(new Field("path", f.getPath(), Field.Store.YES,
				Field.Index.NOT_ANALYZED));

		// Add the last modified date of the file a field named "modified". Use
		// a field that is indexed (i.e. searchable), but don't tokenize the
		// field
		// into words.
		//doc.add(new Field("modified", DateTools.timeToString(f.lastModified(),
		//		DateTools.Resolution.MINUTE), Field.Store.YES,
		//		Field.Index.NOT_ANALYZED));

		String content = org.apache.lucene.termvector.util.File.readUtf8String(f);
		
		//System.out.println(content);
		doc.add(new Field("contents", content, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
		//doc.add(new Field("contents", new FileReader(f), TermVector.YES));


		//System.out.println(doc.getField("contents"));
		// return the document
		return doc;
	}

	private FileDocument()
	{
	}
}